package example.prototype.simple;

import lombok.Data;

import java.util.ArrayList;

@Data
public class ConcretePrototype implements Cloneable {

    public int age;
    public ArrayList<String> list = new ArrayList<>();


     /*  浅拷贝
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }*/

    /**
     * 深拷贝
     *
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        ConcretePrototype prototype = (ConcretePrototype) super.clone();
        prototype.list = (ArrayList) list.clone();
        return prototype;
    }
}
